<template>
  <view>
    <view class="address-box">
      <!-- 选择收货地址的盒子 -->
      <view class="address-choose-box" v-if="JSON.stringify(defaultAddress) === '{}'">
        <button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址</button>
      </view>

      <!-- 渲染收货信息的盒子 -->
      <view class="address-info-box" v-else @click="chooseAddress">
        <view class="row1">
          <view class="row1-left">
            <view class="username">收获人：{{defaultAddress.userName + (defaultAddress.sexType === 1 ? '先生' : '女士')}}</view>
          </view>
          <view class="row1-right">
            <view class="phone">电话：{{defaultAddress.userPhone}}</view>
            <uni-icons type="arrowright" size="16"></uni-icons>
          </view>
        </view>
        <view class="row2">
          <view class="row2-left">收获地址：</view>
          <view class="row2-right">{{addstr}}</view>
        </view>
      </view>

    </view>
    <!-- 底部的边框线 -->
    <image src="/static/stop_imgs/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'vuex'
  export default {
    computed: {
      ...mapState('m_user', ['userinfo', 'defaultAddress']),
      ...mapGetters('m_user', ['addstr']),
    },
    name: "stop-address",
    data() {
      return {

      };
    },
    methods: {
      ...mapMutations('m_user', ['updateAddress']),
      // 选择收货地址
      chooseAddress() {
        if (!this.userinfo.userAddress) {
          uni.navigateTo({
            url: '/subpkg/stop_add_address/stop_add_address'
          })
        } else {
          uni.navigateTo({
            url: '/subpkg/stop_select_address/stop_select_address'
          })
        }
      },
    },
  }
</script>

<style lang="scss">
  .address-box {
    background-color: white;
    margin-bottom: 10px;
    margin-top: 5px;
    border-radius: 15px;
    padding: 0px 5px;
    border: 1px solid #eee;
  }
  // 选择收货地址的盒子
  .address-choose-box {
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;

    .btnChooseAddress {
      background-color: #fba007;
      height: 70rpx;
      line-height: 70rpx;
    }
  }

  // 收货信息的盒子
  .address-info-box {
    font-size: 12px;
    height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 5px;

    .row1 {
      display: flex;
      justify-content: space-between;
      
      .row1-left {
        margin-left: 12px;
      }
      .row1-right {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .row2 {
      display: flex;
      align-items: center;
      margin-top: 10px;

      .row2-left {
        white-space: nowrap;
      }
    }
  }

  // 底部边框线
  .address-border {
    display: block;
    width: 100%;
    height: 5px;
  }
</style>